﻿using KZ.Express.Task;
using KZ.Utilities;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace KZ.Express.Presenter
{
    public interface ICheckPriceView : IViewBase
    {
        DataTable Price { set; }
    }

    public class CheckPricePresenter : PresenterBase
    {
        new ICheckPriceView _view;
        new OrderTask _task;

        public CheckPricePresenter(ICheckPriceView view)
            : base(view)
        {
            _view = view;
            _task = new OrderTask();
        }

        public void LoadPrice(DataTable partnerCarriers, int customerID, int countryID, decimal weight, string type, DateTime date)
        {
            DataTable dt = new DataTable();
            dt.Columns.Add("Number", typeof(int));
            dt.Columns.Add("PartnerName", typeof(string));
            dt.Columns.Add("StandardPrice", typeof(decimal));
            dt.Columns.Add("ListPrice", typeof(decimal));

            int originalPriceListID;//customerPriceListID
            int i = 1;
            foreach (DataRow row in partnerCarriers.Rows)
            {
                DataRow r = dt.NewRow();
                
                r["PartnerName"] = row["PartnerName"];

                int carrierID = Utility.IntParse(row["CarrierID"]);
                int supplierID = Utility.IntParse(row["PartnerID"]);
                if (supplierID > 0)
                {
                    r["Number"] = i++;
                    //decimal standardPrice = _task.LoadOriginalPrice(supplierID, carrierID, countryID, type, weight, date, out originalPriceListID);
                    r["StandardPrice"] = _task.LoadOriginalPrice(supplierID, carrierID, countryID, type, weight, date, out originalPriceListID);
                    //r["ListPrice"] = _task.LoadCustomerPrice(customerID, carrierID, countryID, type, weight, date, out customerPriceListID);
                    //Console.WriteLine(standardPrice);
                    dt.Rows.Add(r);
                }
            }

            _view.Price = dt;
        }
    }
}
